// sum of scores[n], max ,min.
// (1)calculate 函数,求全班成绩的平均分,最高分,最低分.
// (2)count 函数,统计全班各个分数段人数及各自所占总人数的百分比.
// 共分为五个分段:90分以上,80-90,70-79,60-69,60分以下。
// 要求在主函数中输入每人的成绩，调用calcualte和count函数进行分析统计并输出最终结果.

#include <stdio.h>

void calculate(float scores[],int n)
{
    int i;
    float sum1 = 0.0,max1,min1;
    max1 = scores[0];
    min1 = scores[0];
    
    for(i = 0; i < n; i++)
    {
        sum1 += scores[i];
        if(max1 < scores[i])
        {
            max1 = scores[i];
        }
        
        if(min1 > scores[i])
        {
            min1 = scores[i];
        }
    }
    printf("max1 = %.2f min1 = %.2f mean = %.2f",
            max1, min1, sum1/n);
}

void count(float scores[],int n)
{
    int i;
    int cnt = 0;
    int cnt1 = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    int cnt4 = 0;
    float percent1 = 0.0;
    for(i = 0; i < n; i++)
    {
        if(scores[i] > 90)
        {
            cnt++;
        }
        else if(scores[i] >= 80 && scores[i] <= 89)
        {
            cnt1++;
        }
        else if(scores[i] >= 70 && scores[i] <= 79)
        {
            cnt2++;
        }
        else if(scores[i] >= 60 && scores[i] <= 69)
        {
            cnt3++;
        }else if(scores[i] < 60)
        {
            cnt4++;
        }
    }

    printf("\nscore greater than 90: %d -- %%%.2f\n", cnt, (float)(cnt * 100)/n);
    printf("score greater than 80 and less than 89: %d -- %%%.2f\n", cnt1, (float)(cnt1 * 100)/n);
    printf("score greater than 70 and less than 79: %d -- %%%.2f\n", cnt2, (float)(cnt2 * 100)/n);
    printf("score greater than 60 and less than 69: %d -- %%%.2f\n", cnt3, (float)(cnt3 * 100)/n);
    printf("score less than 60: %d -- %%%.2f\n", cnt4, (float)(cnt4 * 100)/n);
}

int main(void)
{
    enum {N = 10};
    int i;
    float scores[N];
    printf("Enter 4 scores:\n");
    for(i = 0; i < N; i++)
    {
        scanf("%f",&scores[i]);
    }
    
    for(i = 0; i < N; i++)
    {
        printf("%.2f ",scores[i]);
    }
    printf("\n");

    calculate(scores,N);
    count(scores,N);
    return 0;
}
